home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 483 / mkrscsrc / wind.c < prev   
Encoding:
C/C++ Source or Header  |  1990-04-29  |  7.0 KB  |  307 lines

  1. #include "stdio.h"
  2. #include "gemdefs.h"
  3. #include "obdefs.h"
  4. #include "osbind.h"
  5. #include "mkrsc.h"
  6. #include "globals.h"
  7.  
  8.  
  9.  /*   redraws the info window    */
  10. int do_redraw(message)
  11.     int message[];
  12. {
  13.     GRECT t1,t2;
  14.     windowptr thewin;
  15.     int  xc, yc, wc, hc;
  16.  
  17.     v_hide_c(handle);
  18.     wind_update(BEG_UPDATE);
  19.  
  20.     xc = message[4];
  21.     yc = message[5];
  22.     wc = message[6];
  23.     hc = message[7];
  24.  
  25. /*    the windows are not resizable so 'work' is constant
  26.  
  27.     thewin = findwindowptr(message[3]);
  28.     wind_get(message[3],WF_WORKXYWH,&thewin->work.g_x,
  29.             &thewin->work.g_y,&thewin->work.g_w,&thewin->work.g_h);
  30. */
  31.  
  32.     t2.g_x=xc;
  33.     t2.g_y=yc;
  34.     t2.g_w=wc;
  35.     t2.g_h=hc;
  36.     wind_get(message[3],WF_FIRSTXYWH,&t1.g_x,&t1.g_y,&t1.g_w,&t1.g_h);
  37.     while (t1.g_w && t1.g_h) {
  38.       if (rc_intersect(&t2,&t1)) {
  39.         set_clip(t1.g_x,t1.g_y,t1.g_w-1,t1.g_h-1);
  40.         update_win(t1.g_x,t1.g_y,t1.g_w-1,t1.g_h-1);
  41.       }
  42.       wind_get(message[3],WF_NEXTXYWH,&t1.g_x,&t1.g_y,&t1.g_w,&t1.g_h);
  43.     }
  44. /*    reset clipping to desktop    */
  45.  
  46.     set_clip(xdesk,ydesk,wdesk,hdesk); /* set_clip to desktop */
  47.  
  48.     wind_update(END_UPDATE);
  49.     v_show_c(handle,1);
  50. }
  51.  
  52. int set_clip(x,y,w,h)
  53. int x,y,w,h;
  54. {
  55. int clip[4];
  56.     clip[0]=x;
  57.     clip[1]=y;
  58.     clip[2]=x+w;
  59.     clip[3]=y+h;
  60.     vs_clip(handle,1,clip);
  61. }
  62.  
  63. windowptr new_window()
  64. {
  65.     int            wihandle, button, dummy, i;
  66.     windowptr    thewin;
  67.  
  68.     /*
  69.         Create the information for the window.  Max size is the desktop.
  70.     */
  71.     wihandle = wind_create(WI_KIND, xdesk, ydesk, wdesk, hdesk);
  72.  
  73.     /*
  74.         Check for error.
  75.     */
  76.     if (wihandle < 0) {
  77.         button = form_alert(1, "[1][ Sorry! | No more windows available. ][OK]");
  78.         return NULL;
  79.     }
  80.  
  81.     /*
  82.         Allocate space for window record.
  83.     */
  84.     thewin                  = (windowptr) malloc(sizeof(windowrec));
  85.     if (thewin == NULL)
  86.     {    button = form_alert(1, "[1][ Sorry! | Out of memory creating window. ][OK]");
  87.         wind_delete(wihandle); /* delete the window created above  */
  88.         return NULL;
  89.     }
  90.  
  91.  
  92.     /*
  93.         Initialize window data structure.
  94.     */
  95.     thewin -> next          = NULL;
  96.     thewin -> wihandle      = wihandle;
  97.     thewin->saved           = TRUE;
  98.  
  99.     thewin -> maintree.objt[0] = *mtbox1;
  100.     thewin -> maintree.objt[0].ob_state = LASTOB;
  101.     thewin -> maintree.count = 0;
  102.     for(i=0;i<MAXONUM;i++)
  103.     {    thewin -> maintree.treelink[i] = NULL;
  104.         thewin -> maintree.kind[i] = 0;
  105.         thewin -> maintree.name[i][0] = NULL;
  106.     }
  107.     thewin -> inwindow = &thewin -> maintree;
  108.  
  109.     sprintf(newtitle,"\\RSC%d.RSC", windowcount++);
  110.     strcpy(thewin->title,newtitle);
  111.     wind_set(thewin->wihandle, WF_NAME, thewin -> title, 0, 0);
  112.  
  113.     /*
  114.         Insert into windowlist.
  115.     */
  116.     {
  117.         register windowptr    winptr = (windowptr) &firstwindow;  
  118.  
  119. /* firstwindow is a pointer to the first windowrec in the linked list and  */
  120. /* is initialized to NULL.  Since the first thing in a windowrec is       */
  121. /* 'next', the pointer to the next windowrec, then                          */
  122. /* '(windowptr)&firstwindow->next' or windptr->next starts at firstwindow */
  123. /* What a kludge to save a bit of code!  Below is some commented out      */
  124. /* tested code that is clearer.                                           */
  125. /*      if(!firstwindow)
  126.           firstwindow = thewin;  
  127.         else                    
  128.         {   winptr = firstwindow;  
  129.              while(winptr -> next) 
  130.             winptr = winptr -> next;
  131.         winptr -> next = thewin;
  132.         }
  133.         
  134. */        
  135.         while(winptr -> next) 
  136.             winptr = winptr -> next;
  137.     
  138.         winptr -> next = thewin;
  139.     }   
  140.         return(thewin);
  141. }
  142.  
  143. open_window(thewin)
  144.     windowptr    thewin;
  145.  
  146. {    graf_growbox(0, 0, 0, 0, xdesk, ydesk, wdesk, hdesk);
  147.     wind_open(thewin->wihandle,160,rez*10,470,rez*185);
  148.  
  149.     wind_get(thewin->wihandle, WF_WORKXYWH, &thewin->work.g_x,
  150.              &thewin->work.g_y, &thewin->work.g_w, &thewin->work.g_h);
  151.  
  152. /*  put the maintree.objt[0] into the window  */
  153.  
  154.     thewin->maintree.objt[0].ob_x = thewin->work.g_x;
  155.     thewin->maintree.objt[0].ob_y = thewin->work.g_y;
  156.     thewin->maintree.objt[0].ob_width = thewin->work.g_w-1;
  157.     thewin->maintree.objt[0].ob_height = thewin->work.g_h-1;
  158.     
  159.     thefrontwin = thewin;
  160.     make_frontwin(thewin);
  161.  
  162. }
  163.  
  164. /*
  165.     dispose_window - Closes the window and disposes the storage for
  166.         the window record.
  167. */
  168. dispose_window(thewin)
  169.     windowptr    thewin;
  170. {
  171.     int x, y, w, h;
  172.  
  173.     wind_close(thewin->wihandle);
  174.     wind_get(thewin->wihandle, WF_CURRXYWH, &x, &y, &w, &h);
  175.     graf_shrinkbox(0, 0, 0, 0, x, y, w, h);
  176.     dispose_win_resources(thewin);
  177.     windowcount--;
  178.  
  179. }
  180.  
  181. dispose_win_resources(thewin)
  182.     windowptr    thewin;
  183. {
  184.         /*
  185.             Remove window record from window list.
  186.         */
  187.         register windowptr    winptr = (windowptr) &firstwindow;
  188.         int button, i;
  189.  
  190.         wind_delete(thewin->wihandle);
  191.  
  192.         while(winptr -> next)
  193.             if (winptr -> next == thewin)
  194.                 break;
  195.             else
  196.                 winptr = winptr -> next;
  197.  
  198.         if (winptr -> next)
  199.             winptr -> next = winptr -> next -> next;
  200.         else {
  201.         button = form_alert(1, "[1][ Internal Error: | Window pointer not in list. ][OK]");
  202.             shutdown(1);
  203.              }
  204.  
  205.         /*
  206.             Update the front window pointer.
  207.         */
  208.         if (!firstwindow)
  209.             thefrontwin = NULL;
  210.         else
  211.             if (winptr == (windowptr) &firstwindow)
  212.                 make_frontwin(winptr -> next);
  213.             else
  214.                 make_frontwin(winptr);
  215.  
  216.         /*  Release storage used by linked object tree structure     */
  217.         
  218.     if(thewin->maintree.count >0)
  219.     for(i = 1;i < (thewin->maintree.count + 1); i++)
  220.             free(thewin->maintree.treelink[i]);
  221.         
  222.         /*    Release window storage.    */
  223.  
  224.         free(thewin);
  225.     
  226. }
  227.  
  228. windowptr findwindowptr(wihandle)
  229.     int wihandle;
  230. {
  231.     register windowptr thewin = firstwindow;
  232.     int button;
  233.  
  234.     for (thewin = firstwindow; thewin; thewin = thewin -> next)
  235.         if (thewin -> wihandle == wihandle)
  236.             break;
  237.  
  238.     if (!thewin) {
  239.         button = form_alert(1, "[1][ Internal Error: | No window found for handle ][OK]");
  240.     }
  241.  
  242.     return thewin;
  243. }
  244.  
  245.  
  246.   /* blank the current window work area */
  247. int whiterect(thewin)
  248.     windowptr thewin;
  249. {
  250.     int pxyarray[4];
  251.  
  252.     v_hide_c(handle);
  253.     vsf_style(handle,4);  
  254.    /* blank to white - may want to change for colour monitor */
  255.     vsf_interior(handle,2);
  256.     pxyarray[0]=thewin->work.g_x;
  257.     pxyarray[3]=thewin->work.g_y;
  258.     pxyarray[2]=thewin->work.g_x+thewin->work.g_w-1;
  259.     pxyarray[1]=thewin->work.g_y+thewin->work.g_h-1;
  260.     vr_recfl(handle,pxyarray);
  261.     v_show_c(handle,1);   
  262.  
  263. /*
  264.     make_frontwin - Force a window to the front.
  265. */
  266. make_frontwin(thewin)
  267.     windowptr thewin;
  268. {
  269.     wind_set(thewin -> wihandle, WF_TOP, 0, 0, 0, 0);
  270.     thefrontwin = thewin;
  271. }
  272.  
  273. rot_wind()
  274. {    windowptr winptr, thewin;
  275.  
  276.  
  277.     if(thewin = thefrontwin)
  278.     {    winptr = firstwindow;  
  279.         while(winptr != thewin) 
  280.             winptr = winptr->next;
  281.         if((winptr =  winptr->next)!=NULL)
  282.             make_frontwin(winptr);
  283.         else
  284.             make_frontwin(firstwindow);
  285.     }
  286. }
  287.  
  288. update_win(cx, cy, cw, ch)
  289.     int    cx, cy, cw, ch;
  290. {
  291.     OBJECT *inwind;
  292.  
  293.     inwind = thefrontwin->inwindow->objt;
  294.     whiterect(thefrontwin);
  295.  
  296.     if(thefrontwin->inwindow->kind[0] == TMENU)
  297.     {
  298.         objc_draw(inwind,1,2,cx,cy,cw,ch);
  299.         if(thefrontwin->inwindow->mbox > 0)     
  300.             objc_draw(inwind,thefrontwin->inwindow->mbox,10,cx,cy,cw,ch);
  301.     }
  302.     else
  303.  
  304.     objc_draw(inwind, 0, 10, cx, cy, cw+1, ch+1);
  305. }
  306.